(function (a2dmah5) {
    a2dmah5.addExpandPage(0, function (get) {
        return {
            expandSetEntityData({ entityData }) {
                let blExists = false;
              
                const accessoryIdList = [];

                for (let i = 0; i < entityData.Details.length; i++) {
                    const id = entityData.Details[i].AccessoryId;
                    if (accessoryIdList.includes(id)) { blExists = true; break; }
                    else accessoryIdList.push(id);
                }

                if(blExists) {
                    this.alert('生产配件有重复添加');
                    return false;
                }

                const materialProductIdList = [];

                for (let i = 0; i < entityData.Details2.length; i++) {
                    const id = entityData.Details2[i].MaterialProductId;
                    if (materialProductIdList.includes(id)) { blExists = true; break; }
                    else materialProductIdList.push(id);
                }

                if(blExists) {
                    this.alert('原料商品有重复添加');
                    return false;
                }

                if(entityData.Details.length===0&& entityData.Details2.length===0){
                    this.alert('生产配件或第三方商品至少有一个明细');
                    return false;
                }

                return entityData;
            }
        }
    });

})(window.a2dmah5);